package com.xubeizhi.controller.system;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.xubeizhi.annotation.OperationLogger;
import com.xubeizhi.common.ResponseResult;
import com.xubeizhi.entity.Dict;
import com.xubeizhi.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 字典表  前端控制器
 *
 * @author mi
 * @create 2023/3/28 13:30
 */
@RestController
@RequestMapping("/system/dict")
@RequiredArgsConstructor
@Api(tags = "字典类型管理")
public class DictController {

    private final DictService dictService;

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @SaCheckLogin
    @ApiOperation(value = "字典列表",httpMethod = "GET",response = ResponseResult.class,notes = "字典列表")
    public ResponseResult listDict(String name, Integer isPublish, String descColumn, String ascColumn) {
        return dictService.listDict(name, isPublish, descColumn, ascColumn);
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @SaCheckPermission("/system/dict/add")
    @ApiOperation(value = "添加字典",httpMethod = "POST",response = ResponseResult.class,notes = "添加字典")
    @OperationLogger(value = "添加字典")
    public ResponseResult insert(@RequestBody Dict dict){
        return dictService.insertDict(dict);
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @SaCheckPermission("/system/dict/update")
    @ApiOperation(value = "修改字典",httpMethod = "POST",response = ResponseResult.class,notes = "修改字典")
    @OperationLogger(value = "修改字典")
    public ResponseResult update(@RequestBody Dict dict){
        return dictService.updateDict(dict);
    }

    @RequestMapping(value = "/delete",method = RequestMethod.DELETE)
    @SaCheckPermission("/system/dict/delete")
    @ApiOperation(value = "删除字典",httpMethod = "DELETE",response = ResponseResult.class,notes = "删除字典")
    @OperationLogger(value = "删除字典")
    public ResponseResult deleteDict(int id){
        return dictService.deleteDict(id);
    }

    @RequestMapping(value = "/deleteBatch",method = RequestMethod.DELETE)
    @SaCheckPermission("/system/dict/deleteBatch")
    @ApiOperation(value = "批量删除字典",httpMethod = "DELETE",response = ResponseResult.class,notes = "批量删除字典")
    @OperationLogger(value = "批量删除字典")
    public ResponseResult deleteBatch(@RequestBody List<Long> ids){
        return dictService.deleteBatch(ids);
    }
}
